<template>
	<view class="report-list">
		<u-navbar title="人力历史" back-icon-color="#fff" title-color="#fff" :background="background"></u-navbar>
		
		<u-picker
			:mode="mode"
			:defaultTime="defaultTime"
			v-model="show"
			:params="params"
			:end-year="endYear"
			@confirm="confirm"
			cancel-text="还原"
			@cancel="cancel"
		></u-picker>
		<!-- 自定时间按钮 -->
		<view class="row-between custom-calendar" @click="showChange">
			<view class="row">
				<view class="calendar-icon">
					<u-icon name="calendar" color="#999" size="22px" ></u-icon>
				</view>
				
				<view class="ml10 lg">
					{{selectText == '' ? '自定义查询' : selectText}}
				</view>
			</view>
			<view class="">
				<u-icon name="arrow-right" color="#999" size="18px" ></u-icon>
			</view>
		</view>
		
		<!-- 列表 -->
		<block v-if="reportList.length > 0">
			<view class="data-list" v-for="(item, index) in reportList" :key="index">
				<view class="row-between data-list-item" @click="clickDevelop" :data-index="index">
					<view class="">
						<view class="">
							{{item.ym}}人力申报账单
						</view>
						<view class="muted sm">
							{{item.createtime}}
						</view>
					</view>
					<view class="row-end">
						<u-icon :name="item.is_develop ? 'arrow-up' : 'arrow-down'" color="#2045fc" size="16px" ></u-icon>
					</view>
				</view>
				
				<view class="list-child" v-show="item.is_develop">
					<view class="row-between list-child-item" v-for="(d_item, d_index) in item.data">
						<view class="child-item">
							{{d_item.job_name}}
						</view>
						<view class="child-item">
							定岗：{{d_item.ren_nums}}人
						</view>
						<view class="child-item">
							薪酬：{{d_item.wage}}元
						</view>
					</view>
				</view>
			</view>
			
			<u-loadmore :status="status" />
		</block>
		<block v-else>
			<u-empty text="当月暂无数据" mode="list" margin-top="80"></u-empty>
		</block>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#2165F7',
				},
				show: false,
				selectText: '',
				mode: 'time',
				endYear: '',
				defaultTime: '',
				params: {
					year: true,
					month: true,
				},
				reportList: [],
				postData: '',
				
				status: 'loadmore',
				page: 1,
				limit: 0,
				isLoading: false,
			}
		},
		onLoad() {
			var date = new Date(),
			year = date.getFullYear(),
			month = date.getMonth() + 1;
			
			this.defaultTime = year + '-' + month;
			this.endYear = year;
			
			this.reportListFun();
			
		},
		onReachBottom() {
			if(this.isLoading) return ;
			this.status = 'loading';
			this.page = ++ this.page;
			setTimeout(() => {
				this.reportListFun();
			}, 2000)
		},
		computed: {
			showBtnStatus() {
				return this.show ? 0 : 1;
			}
		},
		methods: {
			showChange(index) {
				this.show = !this.show;
			},
			confirm(e) {
				this.selectText = '';
				if (this.params.year) this.selectText += e.year;
				if (this.params.month) this.selectText += '-' + e.month;
				
				this.onRefresh();
			},
			cancel(e) {
				this.selectText = '';
				
				this.reportListFun();
			},
			onRefresh() {
				this.status = 'loading';
				this.isLoading = false
				this.page = 1
				this.reportList = [];
				
				this.reportListFun();
			},
			
			//人工成本上报列表
			reportListFun() {
				let _date = this.selectText;
				let post_params = {
					limit: 25,
					page: this.page
				};
				
				if(_date != '') {
					post_params.date = _date
				}
				
				this.$u.post('/api/finance/financeJobMonth', post_params).then(res => {
					let datalist = res.list;
					let _limit = res.limit;
					
					datalist.forEach(function(item,index) {
						item.is_develop = false;
					})
					if(datalist.length < _limit) {
						this.status = 'nomore';
						this.isLoading = true;
					}
					this.reportList = this.reportList.concat(datalist);
					this.limit = _limit;
				});
			},
			
			clickDevelop(e) {
				let _this = this;
				let _index = e.currentTarget.dataset.index;
				let _list = _this.reportList;
				
				_list[_index].is_develop = !_list[_index].is_develop;
				
				_this.reportList = _list;
				
			}
		}
	}
</script>

<style lang="scss">
	.report-list {
		
		.custom-calendar {
			padding: 30rpx;
			.calendar-icon {
				position: relative;
				
				&::after {
					content: "";
					position: absolute;
					width: 10rpx;
					height: 10rpx;
					border-radius: 50%;
					background-color: #de2626;
					top: 0;
					right: 0;
				}
			}
		}
		
		.data-list {
			border-bottom: 2rpx solid #f6f6f6;
			.data-list-item {
				padding: 20rpx 30rpx;
			}
			
			.list-child {
				.list-title {
					padding: 20rpx;
					background-color: #f6f6f6;
				}
				
				.list-child-item {
					padding: 30rpx;
					border-bottom: 2rpx solid #f6f6f6;
					
					.child-item {
						width: 33.33%;
						
						&:nth-child(2) {
							text-align: center;
						}
						
						&:nth-child(3) {
							text-align: right;
						}
					}
				}
				
			}
		}
	}
</style>
